//
//  SPVerticalLayoutBtn.m
//  panzer
//
//  Created by 还带大道 on 2018/10/19.
//  Copyright © 2018年 还带大道. All rights reserved.
//

#import "SPVerticalLayoutBtn.h"
#import "UIView+Extension.h"
#import "SPCommon.h"

#define RZTabBarCustomButtonImageScale 0.55

@implementation SPVerticalLayoutBtn

//只需要设置一次的属性
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self){
        
        //设置文字居中
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self setTitleColor:RZ_COLOR(74, 74, 74) forState:UIControlStateNormal];
        [self setTitleColor:RZ_COLOR(254, 220, 69) forState:UIControlStateSelected];
        self.titleLabel.font = [UIFont systemFontOfSize:10];
        
//        self.imageView.backgroundColor = [UIColor yellowColor];
//        self.titleLabel.backgroundColor = [UIColor redColor];
        
//        //设置图片
//        self.imageView.contentMode = UIViewContentModeBottom;
//        //设置字体大小
//        CGFloat fontSize = 12;
//        self.titleLabel.font = [UIFont systemFontOfSize:fontSize];
//        //设置文字颜色
//        [self setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
//        [self setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
        
//        //添加新消息提示
//        _news_btn = [UIButton new];
//        _news_btn.frame = CGRectMake(0, -4, 20, 20);
//        _news_btn.hidden = YES;
//        _news_btn.titleLabel.font = [UIFont systemFontOfSize:fontSize];
//        _news_btn.backgroundColor = [UIColor redColor];
//        _news_btn.layer.cornerRadius = _news_btn.frame.size.width * 0.5;
//        _news_btn.clipsToBounds = YES;
//        [self addSubview:_news_btn];
        
    }
    
    return self;
}


//设置item
-(void)setItem:(UITabBarItem *)item
{
    _item = item;
    //设置文字
    [self setTitle:self.item.title forState:UIControlStateNormal];
    [self setTitle:self.item.title forState:UIControlStateSelected];
    //NSLog(@"%@",self.item.title);
    
    //设置图片
    [self setImage:self.item.image forState:UIControlStateNormal];
    [self setImage:self.item.selectedImage forState:UIControlStateSelected];
}



//重写去掉高亮状态
-(void)setHighlighted:(BOOL)highlighted{};


////图片按钮中的位置
//- (CGRect)imageRectForContentRect:(CGRect)contentRect
//{
//    CGFloat imageW = contentRect.size.width;
//    CGFloat imageH = contentRect.size.height * RZTabBarCustomButtonImageScale;
//    return CGRectMake(0, 0, imageW, imageH);
//}
//
//
////标题在按钮中的位置
//- (CGRect)titleRectForContentRect:(CGRect)contentRect
//{
//    CGFloat titleW = contentRect.size.width;
//    CGFloat titleY = contentRect.size.height * RZTabBarCustomButtonImageScale;
//    CGFloat titleH = contentRect.size.height - titleY;
//    return CGRectMake(0, titleY, titleW, titleH);
//}


- (void)layoutSubviews
{
    [super layoutSubviews];
    CGRect rect_imageV = self.imageView.frame;
    CGRect rect_label = self.titleLabel.frame;
    
    rect_imageV.origin.x = (self.width - rect_imageV.size.width)*0.5;
    rect_imageV.origin.y = 10;
    
    rect_label.origin.x = (self.width - rect_label.size.width)*0.5;
    rect_label.origin.y = CGRectGetMaxY(rect_imageV)+4;
    
    self.imageView.frame = rect_imageV;
    self.titleLabel.frame = rect_label;
}

@end
